package com.hh.game.service.gateway.filter.ip;

import com.hh.game.service.gateway.utils.IpUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.net.SocketAddress;

public class BlackIpFilter extends ChannelInboundHandlerAdapter {

    @Override
    public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
        String ip = IpUtil.getIp(ctx);
        if (IPContainer.isBlackIP(ip)) {
            ctx.close();
            return;
        }
        super.channelRegistered(ctx);
    }

//    @Override
//    public void channelActive(ChannelHandlerContext ctx) throws Exception {
//        String address = ctx.channel().remoteAddress().toString();
//        if (IPContainer.isBlackIP(address)) {
//            ctx.close();
//        } else {
//            super.channelActive(ctx);
//        }
//    }
}
